// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.asset;

import zombie.fileSystem.FileSystem;
import zombie.fileSystem.IFile;
import zombie.fileSystem.IFileTask2Callback;

final class AssetTask_LoadFromFileAsync extends AssetTask implements IFileTask2Callback {
    int m_async_op = -1;
    boolean bStream;

    AssetTask_LoadFromFileAsync(Asset asset, boolean _boolean) {
        super(asset);
        this.bStream = _boolean;
    }

    @Override
    public void execute() {
        FileSystem fileSystem = this.m_asset.getAssetManager().getOwner().getFileSystem();
        int _int = 4 | (this.bStream ? 16 : 1);
        this.m_async_op = fileSystem.openAsync(fileSystem.getDefaultDevice(), this.m_asset.getPath().m_path, _int, this);
    }

    @Override
    public void cancel() {
        FileSystem fileSystem = this.m_asset.getAssetManager().getOwner().getFileSystem();
        fileSystem.cancelAsync(this.m_async_op);
        this.m_async_op = -1;
    }

    @Override
    public void onFileTaskFinished(IFile iFile, Object object) {
        this.m_async_op = -1;
        if (this.m_asset.m_priv.m_desired_state == Asset.State.READY) {
            if (object != Boolean.TRUE) {
                this.m_asset.m_priv.onLoadingFailed();
            } else if (!this.m_asset.getAssetManager().loadDataFromFile(this.m_asset, iFile)) {
                this.m_asset.m_priv.onLoadingFailed();
            } else {
                this.m_asset.m_priv.onLoadingSucceeded();
            }
        }
    }
}
